package com.hippomeetsskunk.savanna.types.meta;

import java.util.HashSet;
import java.util.Set;

/**
 * all objects in the simulation, could sometimes reduce to classes
 * @author SRZCHX
 * note: enum can not be extended
 */
public abstract class SimObjectType {

	private final String type;
	private final SimObjectType parent;
	
	protected SimObjectType(String type, SimObjectType parent){
		this.type = type;
		this.parent = parent;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SimObjectType other = (SimObjectType) obj;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
	
	public static <T> Set<T> createSet(T ... t){
		if (t==null) return null;
		Set<T> types = new HashSet<T>();
		for(T a : t){
			types.add(a);
		}
		return types;
	}

	@Override
	public String toString() {
		return type.toString();
	}
	
	public boolean isA(SimObjectType other){
		if (equals(other)) return true;
		if (parent != null) return parent.isA(other);
		return false;
	}

	protected SimObjectType getParent() {
		return parent;
	}
}
